home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / batchlrn.arc / FORINDO.HLP < prev    next >
Text File  |  1991-06-17  |  7KB  |  91 lines

  1. |---------------B A T C H L R N  H E L P  S Y S T E M-----------------|
  2. |command: FOR..IN..DO (Actually multiple commands)                    |
  3. |use:FOR..IN..DO string is used to expand the power of a batch file   |
  4. | or as an interactive (from the keyboard prompt) command             |
  5. |                                                                     |
  6. |how: In Batch processing type: FOR %%<c>IN<set>DO<command>           |
  7. |     In Interactive processing type: FOR %<c>IN<set>DO<command>      |
  8. |                                                                     |
  9. |explanation: The FOR command is similar to the "for..next loop" that |
  10. | programmers use to repeat a paricular action a number of times. A   |
  11. | batch file to compare files on A:& B: drives looks like this:       |
  12. |    ECHO OFF        [keeps command clutter of the screen]            |
  13. |    CLS             [we always do this to get ECHO OFF removed]      |
  14. |    FOR %%Y IN (*.*) DO IF EXIST B:%%Y ECHO %%Y IS ON BOTH A:&B:     |
  15. |    |       |        |=the<command>(here, starting on A:drive,the    |
  16. |    |       |         DO sees if X {which is *.*[any of all the      |
  17. |    |       |         files on A:]} exists on B: the ECHOes the      |
  18. |    |       |         file name {X} as being on "BOTH A:&B:")        |
  19. |    |       |                                                        |
  20. |    |       |=IN<set> the set is *.* or all the files on A:&B:       |
  21. |    |                                                                |
  22. |    |=FOR is seeking the variable %X (it could be any letter)        |
  23. |                                                                     |
  24. |                                               |
  25. |examples: FOR %%gf IN(*.ASM)DO MASM %%f;                             |
  26. | FOR %%f IN(BAK ART BUDGT) DO REM %%f                                |
  27. | The "%%" is needed so that after batch parameter (%0-%9) processing |
  28. | is complete, a % remains. If only %f was entered, the DOS batch pa- |
  29. | rameter processor sees the first "%", looks at "f", then decides    |
  30. | that "%f" is a bad parameter reference, and discards the "%f".      |
  31. | The FOR command would never receive this parameter. In a batch      |
  32. | file, you must use the expression "%%".                             |
  33. | Let's see hoe the batch command works... The first line turns       |
  34. | command displat off to clear command clutter. The second line clears|
  35. | the "echo off" messagefrom the screen. The third line is executed   |
  36. | many times as there are files on the disk in a: [the set (*.*)      |
  37. | assures this]. Each of those filenamesare assigned to %%Z in turn   |
  38. | and then checked for presence on drive B: with the EXIST logical    |
  39. | statement. If EXIST is true, then the message at the end of the IF  |
  40. | subcommand si sent to the screen, otherwise nothing is printed and  |
  41. | the next file on driove A: is assigned and checked.                 |
  42. |   FILES on drive A:               FILES on drive B:                 |
  43. |   -----------------               ------------------                |
  44. |     COMMAND.COM                      COMMAND.COM                    |
  45. |     FILE.ONE                         FILE.ONE                       |
  46. |     FILE.TWO                         FILE.LTR                       |
  47. | The batch subcommand we are investigating is:                       |
  48. | FOR %%Z IN (*.*) DO IF EXIST B:%%Z is on both A: and B:             |
  49. | Each filename on A: is substitutedin the IF subcommand and then     |
  50. | executed. To get the same effect you would have to type--           |
  51. | IF EXIST B:COMMAND.COM ECHO COMMAND.COM is on both A: and B:        |
  52. | IF EXIST B:FILE.ONE ECHO FILE.ONE is on both A: and B:              |
  53. | IF EXIST B:FILE.TWO ECHO FILE.TWO is on both A: and B:              |
  54. | In the case of the example above, the first two would have a posi-  |
  55. | tive responseand the last would not print anything. Study it care-  |
  56. | fully before going on.                                              |
  57. |           FILES on drive A:             FILES on drive B:           |
  58. |           -----------------             -----------------           |
  59. |            COMMAND.COM                   COMMAND.COM                |
  60. |            FILE.ONE                      FILE.ONE                   |
  61. |            FILE.TWO                      FILE.LTR                   |
  62. | OK, told you to studt the example. Let's see if you remember. What  |
  63. | is the one line batch file command to find and report out all files |
  64. | starting with an "F" on drive A:? [I'll help you a little, you fill |
  65. | in the blanks.]                                                     |
  66. | ___%%Z IN (A:_____) ____ECHO File_____is on drive A:                |
  67. | FOR %%Z IN (A:F*.*) DO ECHO File %%Z is on drive A:                 |
  68. | In this case you see that the A: disk is checked for any file start-|
  69. | ing with the letter "F" and that name is substituted in the varible |
  70. | %%Z. The appropriate message is then printed with the proper file-  |
  71. | name.                                                               |
  72. | This is not an easy concept. Let's now look at using DOS commands   |
  73. | in (Set).                                                           |
  74. |                FOR...IN..DO using DOS Commands                      |
  75. |                ================================                     |
  76. |  The set can contain DOS commands instead of filenames and these    |
  77. | commands will then be executed in sequence (to include running      |
  78. | large programes under the control of the FOR..IN..DO loop).         |
  79. | Let's say you want to sequentially:  Clear the screen               |
  80. |                                      Show the DOS version number    |
  81. |                    then  Show the disk directory with the pause on  |
  82. | You could do all that in a one line batch file with the following   |
  83. | command in it:: FOR %%T IN (CLS VER DIR/P) DO %%T                   |
  84. | When using DOS commands in (SET) ypu must use the space as a de-    |
  85. | limiter and cannot have asterisk (*) or question mark (?) in any    |
  86. | command. Use a colon(:) instead of a space when passing parameters  |
  87. | to programs (i.e. DBASE:FILE INSTEAD OF DBASE FILE)                 |
  88. | It is possible to issue the FOR..IN..DO command at the DOS prompt   |
  89. | by dropping one of the percentage signs (%) an the varible.         |
  90. |----------------- T  I  M  E  M  A  S  T  E  R  ---------------------|
  91.